/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BajaBovino.java
 *
 * Created on 06-feb-2012, 16:51:25
 */
package formularios;

import clases.abmBovino;
import javax.swing.JOptionPane;

/**
 *
 * @author Ele
 */
public class BajaBovino extends javax.swing.JDialog {

    /** Creates new form BajaBovino */
    public BajaBovino(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfNumeroId = new javax.swing.JTextField();
        btnBajaAnimal = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Baja bovino");

        jLabel1.setText("Ingrese el número de identificación del animal:");

        btnBajaAnimal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/ok.png"))); // NOI18N
        btnBajaAnimal.setText("Aceptar");
        btnBajaAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBajaAnimalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfNumeroId, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(148, Short.MAX_VALUE)
                .addComponent(btnBajaAnimal)
                .addGap(144, 144, 144))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfNumeroId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(btnBajaAnimal)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-407)/2, (screenSize.height-167)/2, 407, 167);
    }// </editor-fold>//GEN-END:initComponents

    private void btnBajaAnimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBajaAnimalActionPerformed
     String numero= tfNumeroId.getText().trim();
     if (numero.equals("")){
         JOptionPane.showMessageDialog(null,"Por favor ingrese el número de identificador","Aviso",JOptionPane.INFORMATION_MESSAGE);
         
     }
     else{
         
        if (new abmBovino().ExisteBovino(numero)){
        
        int num= Integer.parseInt(numero);
        int op= JOptionPane.showConfirmDialog(null,"¿Está seguro de eliminar el animal? \n Si acepta no podra ver nunca más los datos del animal","Confirmación",JOptionPane.YES_NO_OPTION);
        
            if (op==JOptionPane.YES_OPTION){
                new abmBovino().BajaAnimal(num);
                this.dispose();
   }
            else{
                this.dispose();
                        
            }
        }
                else{
                    JOptionPane.showMessageDialog(null,"El número de identificación ingresado no existe","Aviso",JOptionPane.INFORMATION_MESSAGE);
                      tfNumeroId.setText("");
                } 
        
     }
    }//GEN-LAST:event_btnBajaAnimalActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BajaBovino.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BajaBovino.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BajaBovino.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BajaBovino.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                BajaBovino dialog = new BajaBovino(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBajaAnimal;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField tfNumeroId;
    // End of variables declaration//GEN-END:variables
}
